<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/common_tag.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>权限—资源管理</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	
  </head>
  
  <body>
  <script type="text/javascript">
  /** 添加-权限资源表格dialog  */
  function resources_add_dlg_Fun() {
	  var url='${ctx}/security/resources_add.jsp';
	  if($('#dg_table').treegrid('getSelected')){
		  var id = $('#dg_table').treegrid('getSelected')['id'];
		  if(id!=''){
			  url = '${ctx}/security/resources_add.jsp?id='+id;
		  }
	  }
		$('<div/>').dialog({
			href : url,
			width : 350,
			iconCls:'icon-save',
			height : 450,
			modal : true,
			title : '添加资源',
			buttons : [ {
				text : '保存',
				iconCls:'icon-save',
				handler : function() {
					var d = $(this).closest('.window-body');
					$('#resources_addForm').form('submit', {
						url : '${ctx}/security/security_addResources.do',
						onSubmit: function () {
		                    return $(this).form('validate');
		                 },
						success : function(data) {
							d.dialog('destroy');
					    	$('#dg_table').treegrid('reload');
					        $.messager.alert('提示',data,'info');
						}
					});
				}
			}, {
				text : '取消',
				iconCls : 'icon-cancel',
				handler : function() {
					$(this).closest('.window-body').dialog('close');
				}
			}],
			onClose : function() {
				$(this).dialog('destroy')
			}
		});
	}

  /** 编辑修改-权限资源表格dialog  */
  function resources_edit_dlg_Fun() {
	  var id = $('#dg_table').treegrid('getSelected')['id'];
	  if(id=='')return;
		$('<div/>').dialog({
			href : '${ctx}/security/security_iniEditRole.do?id='+id,
			width : 350,
			height : 450,
			iconCls:'icon-save',
			modal : true,
			title : '添加资源',
			buttons : [ {
				text : '保存',
				iconCls:'icon-save',
				handler : function() {
					var d = $(this).closest('.window-body');
					$('#resources_addForm').form('submit', {
						url : '${ctx}/security/security_editRes.do',
						onSubmit: function () {
		                    return $(this).form('validate');
		                 },
						success : function(data) {
		                	var data = JSON.parse(data);
					        $.messager.alert('提示',data.msg,'info');
					        $('#dg_table').treegrid('reload');
					        d.dialog('destroy');
						}
					});
				}
			}, {
				text : '取消',
				iconCls : 'icon-cancel',
				handler : function() {
					$(this).closest('.window-body').dialog('close');
				}
			}],
			onClose : function() {
				$(this).dialog('destroy')
			}
		});
	}
  /** 删除-权限资源  */
  function resources_del_Fun() {
	  	if($('#dg_table').treegrid('getSelected')==null)return;
		var id = $('#dg_table').treegrid('getSelected')['id'];
		$.ajax({
			  type: 'POST',
			  url: '${ctx}/security/security_deleteRes.do',
			  data: { 'id': id } ,
			  success: function(data) {
			    	$('#dg_table').treegrid('reload');
			        $.messager.alert('提示',data,'info');
					
			  }
		});
	}
  </script>
  <!-- 列表表格  开始 -->
  <table id="dg_table" class="easyui-treegrid" width="100%" height="100%"
			data-options="url: '${ctx}/security/security_getResourcesJson.do',
						singleSelect:true,
						rownumbers: true,
						fitColumns:true,
						fit:true,
						idField:'id',  
    					treeField:'text',
						toolbar: [{
								text:'新增',
								iconCls: 'icon-add',
								handler:function(){
									resources_add_dlg_Fun()
								}
							},{
								text:'编辑',
								iconCls: 'icon-edit',
								handler:function(){
									resources_edit_dlg_Fun()
								}
							},{
								text:'删除',
								iconCls: 'icon-remove',  
								handler:function(){
									resources_del_Fun()
						   		}
						   	},{
								text:'刷新',
								iconCls: 'icon-reload',  
								handler:function(){
										$('#dg_table').treegrid('reload');
								}
							}] ">
		<thead>
			<tr>
				<th data-options="field:'text',width:100">名称</th>
				<th data-options="field:'link',width:120">链接</th>
				<th data-options="field:'memo',width:120">说明</th>
				<th data-options="field:'attr1',width:100">操作</th>
			</tr>
		</thead>
  </table>
  <!-- 列表表格  结束 -->
  </body>
</html>
